package com.pro.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import com.pro.entity.BannerEntity;
import com.pro.entity.CompanyEntity;
import com.pro.util.DBManager;
import com.pro.util.QueryResult;

public class CompanyDaoImpl {
	//查询公司信息
	public CompanyEntity companyDetail(){
		CompanyEntity cEntity= null;
	    String sqlString="select id,create_time,company_intr,company_culture,tel,address,phone,email,img,name,logo,url,x,y from company";
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	        	  cEntity=new CompanyEntity(rSet.rs.getInt("id"),
	            		rSet.rs.getDate("create_time"),
	            		rSet.rs.getString("company_intr"),
	            		rSet.rs.getString("company_culture"),
	            		rSet.rs.getString("tel"),
	            		rSet.rs.getString("address"),
	            		rSet.rs.getString("phone"),
	            		rSet.rs.getString("email"),
	            		rSet.rs.getString("img"),
	            		rSet.rs.getString("name"),
	            		rSet.rs.getString("logo"),
	            		rSet.rs.getString("url"),
	            		rSet.rs.getString("x"),
	            		rSet.rs.getString("y"));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return cEntity;
	}
	//查询公司信息
	public ArrayList<CompanyEntity> companyAll(){
		ArrayList<CompanyEntity> alist= new ArrayList<CompanyEntity>();//集合
	    String sqlString="select id,create_time,company_intr,company_culture,tel,address,phone,email,img,name,logo,url,x,y from company";
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	            alist.add(new CompanyEntity(rSet.rs.getInt("id"),
	            		rSet.rs.getDate("create_time"),
	            		rSet.rs.getString("company_intr"),
	            		rSet.rs.getString("company_culture"),
	            		rSet.rs.getString("tel"),
	            		rSet.rs.getString("address"),
	            		rSet.rs.getString("phone"),
	            		rSet.rs.getString("email"),
	            		rSet.rs.getString("img"),
	            		rSet.rs.getString("name"),
	            		rSet.rs.getString("logo"),
	            		rSet.rs.getString("url"),
	            		rSet.rs.getString("x"),
	            		rSet.rs.getString("y")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	//修改
	 public int companyUpdate(CompanyEntity cEntity) {
	 		String sqlString="update company set create_time='"+cEntity.getCreateTime()+"',company_intr='"+cEntity.getCompanyIntr()+"',company_culture='"
	 				+cEntity.getCompanyCulture()+"',tel='"+cEntity.getTel()+"',address='"+cEntity.getAddress()+"'"
	 						+ ",phone='"+cEntity.getPhone()+"',email='"+cEntity.getEmail()+"'"
	 						+ ",img='"+cEntity.getImg()+"',name='"+cEntity.getName()+"'"
	 						+ ",logo='"+cEntity.getLogo()+"',url='"+cEntity.getUrl()+"'"
	 								+ ",x='"+cEntity.getX()+"',y='"+cEntity.getY()+"' where id = '"+cEntity.getId()+"'";
	 		 int result= DBManager.executeUpdate(sqlString);
	 		return result;
	 	}
}
